package com.myccb.app.view.investment;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.WindowManager;

/**
 * Created by freak on 17-12-5.
 */

public class DrawRect extends View {
    WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int width = windowManager.getDefaultDisplay().getWidth();
    Paint paint = new Paint();
    RectF rectf = new RectF(-25, 0, 25, 50);
    Path path = new Path();

    public DrawRect(Context context) {
        super(context);
    }

    public DrawRect(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);

        switch (widthMode){
            case MeasureSpec.AT_MOST:
                widthSize = width/5;
                break;
            case MeasureSpec.EXACTLY:
                break;
            case MeasureSpec.UNSPECIFIED:
                break;
        }

        switch (heightMode) {
            case MeasureSpec.AT_MOST:
                heightSize = heightSize/4;
                break;
            case MeasureSpec.EXACTLY:
                break;
            case MeasureSpec.UNSPECIFIED:
                break;
        }

        setMeasuredDimension(widthSize, heightSize);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.rgb(208, 16, 76));
        canvas.translate(getWidth()/2, 0);

        path.lineTo(25, 0);
        path.lineTo(25, 25);

        path.addArc(rectf, 0, 180);
        path.lineTo(-25, 0);
        path.lineTo(0, 0);
        canvas.drawPath(path, paint);

        paint.setColor(Color.BLACK);
        paint.setTextSize(30);
        canvas.drawText("荐", -15, 30, paint);
    }
}
